#delimit;
use 20161021_Working_hh_1014.dta, clear;
keep if year>=2011 & year<=2015;
drop if FIPS==11;

egen GROUP=rank(Y), unique;
replace GROUP=round(GROUP/(_N/100));
sort GROUP;                           
collapse year Y totalTransfers hh_incwel hh_SNAP hh_incgovwk hh_incunemp hh_eitc hh_ctc hh_inceng 
	socialInsurance credit transfers CPIU2016, by(GROUP);


gen assistance_bar = ((socialInsurance + credit + transfers)/1000)*CPIU2016 ;
label var assistance_bar "Social Assistance";

gen eitc_bar = ((socialInsurance + credit)/1000)*CPIU2016;
label var eitc_bar "EITC & CTC";

gen insurance_bar= (socialInsurance/1000)*CPIU2016;
label var insurance_bar "Social Insurance";

*replace Y=(Y/1000)*CPIU2016;

set scheme s1mono;	
graph drop _all;

			twoway bar assistance_bar Y if Y<=50, barwidth(1) color("gs12")
				|| bar eitc_bar Y if Y<=50, barwidth(1) color("gs8")
				|| bar insurance_bar Y if Y<=50, barwidth(1) color("gs2")
    				legend(size(vsmall) region(lc(gs16))) 
    				xtitle("Market Income ($1000s)", size(medium)) 
    				ytitle("Social Transfers ($1000s)", size(medium))
    				legend( col(1) ring(0) pos(2) size(small))
    				xlabel(0(10)50)
					ylabel(0(2)8);
					
graph save "20161021_Fig1_1014_US_bar.gph", replace;
graph export "20161021_Fig1_1014_US_bar.pdf", replace fontface("Helvetica");

